package com.offer;

import com.bean.ListNode;
import com.utils.DataUtils;

public class Test25 {

    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode resultNoe = new ListNode();
        ListNode dummyNode = resultNoe;

        while (l1 != null && l2 != null) {
            if (l1.val <= l2.val) {
                resultNoe.next = l1;
                l1 = l1.next;
            } else {
                resultNoe.next = l2;
                l2 = l2.next;
            }
            resultNoe = resultNoe.next;
        }

        if (l1 != null) {
            resultNoe.next = l1;
        }

        if (l2 != null) {
            resultNoe.next = l2;
        }

        return dummyNode.next;
    }

    public static void main(String[] args) {
        Test25 test25 = new Test25();

        ListNode listNode1 = DataUtils.getOneToNumberListNode(3);
        ListNode listNode2 = DataUtils.getOneToNumberListNode(3);
        ListNode result = test25.mergeTwoLists(listNode1, listNode2);
        DataUtils.printListNode(result);
    }

}
